package com.objectdraw.client.objectdraw;
import java.awt.*;
import java.awt.event.*;

/**
 * Handles mouse events from drawing canvas
 * 
 * @author jgulik, cfruehan
 *
 */
public class DrawingCanvasListener 
implements MouseListener, MouseMotionListener {

	protected DrawingCanvas canvas;
	protected Point startingMousePosition;

	/**
	 * instantiates drawingcanvaslistener.  
	 * @param canvas the cavas to which the object is listening
	 */
	public DrawingCanvasListener(DrawingCanvas canvas) {
		this.canvas=canvas;
	}

	/**
	 * Handles mousePressed events.  Passes the event to the appropriate tool. 
	 * Sends coords from mouse event to server.
	 */
	public void mousePressed(MouseEvent e) {
		Tool tool = canvas.getCurrentTool();
		if (tool != null && canvas.control) {
			tool.mousePressed(e);
			canvas.com.sendMessage("mouse pressed "+e.getPoint().x+" "+e.getPoint().y);
		}
	}

	/**
	 * Handles mouseReleased events.  Passes the event to the appropriate tool. 
	 * Sends coords from mouse event to server.
	 */
	public void mouseReleased(MouseEvent e) { 
		Tool tool = canvas.getCurrentTool();
		if(tool != null && canvas.control) {
			tool.mouseReleased(e);
			canvas.com.sendMessage("mouse released "+e.getPoint().x+" "+e.getPoint().y);
		}
	}

	/**
	 * Handles mouseDragged events.  Passes the event to the appropriate tool. 
	 * Sends coords from mouse event to server.
	 */
	public void mouseDragged(MouseEvent e) {
		Tool tool = canvas.getCurrentTool();
		if(tool != null && canvas.control) {
			tool.mouseDragged(e);
		}
	}

	/* Null listener methods */

	/**
	 * unimplemented
	 */
	public void mouseClicked(MouseEvent e) {}
	/**
	 * unimplemented
	 */
	public void mouseEntered(MouseEvent e) {}
	/**
	 * unimplemented
	 */
	public void mouseExited(MouseEvent e) {}
	/**
	 * unimplemented
	 */
	public void mouseMoved(MouseEvent e) {}

} /* end of class DrawingCanvasListener */
